package so.sao.code.service.domain;

import org.springframework.http.HttpStatus;

import so.sao.code.service.domain.entity.TagBatch;
import so.sao.code.service.infrastructure.enums.CodeMessage;
import so.sao.sso.common.CommonConstants;
import so.sao.sso.feign.dto.UserDTO;
import so.sao.top.core.util.rest.RestException;

/**
 * Created by Administrator on 2017/9/13.
 */
public class ValidateUtils {

	public static void tagActivecheck(UserDTO user, TagBatch tagBatch) {
		tagBatch.checkTagBatchConfig();
		checkUser(user, tagBatch);
	}

	private static void checkUser(UserDTO user, TagBatch tagBatch) {
		// 管理员用户
		if (CommonConstants.SYSTEM_INNER_ESEID.equals(user.getEseId()))
			return;
		if (!user.getEseId().equals(tagBatch.getEseId()) || !user.getEseId().equals(tagBatch.getEseId())) {
			throw new RestException(HttpStatus.BAD_REQUEST, CodeMessage.InvalidRequest);
		}
	}

	public static boolean isInRange(long now, long start, long end) {
		if (now >= start && now <= end) {
			return true;
		}
		return false;
	}
}
